using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace PopLava.Tools
{
    class XmlHelper
    {
        private XmlDocument g_xmlDocument;
        public XmlHelper(ref XmlDocument xmlSavedSettings)
        {
            g_xmlDocument = xmlSavedSettings;
        }
        /// <summary>
        /// Returns an xmlnode for the specified tile
        /// </summary>
        public XmlNode GetTileNode(string sTileName, string sCurrentViewId)
        {
            XmlNodeList xmlViews = g_xmlDocument.DocumentElement.GetElementsByTagName("view");
            foreach (XmlNode xmlNodes in xmlViews)
            {
                if (xmlNodes.FirstChild.InnerText == sCurrentViewId)
                {
                    foreach (XmlNode n1 in xmlNodes)
                    {
                        if (n1 == null || n1.Name.Length == 0)
                        {
                            MessageBox.Show("Fatal error occured while reading WinClickPro.xml (" + n1.Name + ")");
                            Environment.Exit(0);
                        }
                        if (n1.Name == "tile" && n1.FirstChild.InnerText == sTileName)
                        {
                            return n1;
                        }
                    }
                }
            }
            return null;
        }
    }
}
